#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<thread>
#include <limits>
#include <unordered_map>
#include <queue>
#include<graphics.h>
#include<stack>
#include<assert.h>
#include <stdlib.h>
#include<windows.h>
using namespace std;
#define Size 10
#define INF 0x3f3f3f3f
//窗口大小
#define w_width 1000
#define w_height 680
//按钮统一大小
#define b_width 80
#define b_height 50

#define IDName "202407"
#define IDpassward "123456"
//按钮个数
static int num = 0;
static int order = -1;

string s_allpath = "";
string s_shortpath = "";
string Notice = "";
//按钮封装
struct Button
{
public:
	int x;
	int y;
	int width;
	int height;
	COLORREF outColor;
	COLORREF inColor;
	string text;
	COLORREF textColor;
	Button(int x, int y, int width, int height, const string text);
};
void drawbuttonarea(Button& b);
void detbutton(Button& b);
int clickButton(Button& b, ExMessage m);


	// 定义地点结构体，包含名称、描述和与其它地点的连接道路
	struct Place {
		string name;  // 地点名称
		string info;  // 地点描述
		int x;
		int y;
		int width;
		int height;
		IMAGE img;
		LPCTSTR pfile;
		unordered_map<int, int> roads; //(索引, 距离)
	};
class CampusMap
{
private:

	// 使用unordered_map存储所有地点信息，键为地点名称，值为地点结构体
	unordered_map<string, Place> places;
	int numPlaces;   // 用于记录当前地图中地点的数量

	// 根据地点名称获取地点在places中的索引
	int getIndex(const string& place) {
		return distance(places.begin(), places.find(place));  // 使用distance计算距离
	}

	// 根据地点索引获取地点名称
	string getPlaceName(int index) {
		// 使用迭代器 
		auto it = places.begin();
		advance(it, index);
		return it->first;  // 返回迭代器指向的地点名称
	}

	// 移除两个地点之间的道路连接
	void removeRoad(int index1, int index2) {
		// 获取第一个地点的道路连接
		auto& roads1 = places[getPlaceName(index1)].roads;
		// 删除指向第二个地点的道路连接
		roads1.erase(index2);
	}

	// 采用DFS，找到所有从当前地点到目的地点的路径
	void dfs(const string& current, const string& destination, vector<string>& currentPath, vector<vector<string>>& allPaths, unordered_map<string, bool>& visited) {
		if (current == destination) { // 如果当前地点是目的地点
			allPaths.push_back(currentPath);  // 将当前路径添加到所有路径中
			return;  // 结束递归
		}
		// 标记当前地点为已访问
		visited[current] = true;

		for (const auto& neighbor : places[current].roads) { // 遍历当前地点的所有相邻地点
			string nextPlace = getPlaceName(neighbor.first); // 获取相邻地点的名称
			if (!visited[nextPlace]) { // 如果相邻地点未被访问
				currentPath.push_back(nextPlace);  // 将相邻地点添加到当前路径
				dfs(nextPlace, destination, currentPath, allPaths, visited);  // 递归调用dfs
				currentPath.pop_back(); // 回溯，移除当前相邻地点
			}
		}
		// 回溯，取消当前地点的访问标记
		visited[current] = false;
	}

public:
	// 构造函数，初始化地点数量为0
	CampusMap() : numPlaces(0) {}
	// 添加一个新地点到地图中
	void initPlace(const string& place, const string& info, int x, int y, int width, int height, LPCTSTR pfile) {
		// 如果地点名称在映射中不存在，则添加新地点
		if (places.find(place) == places.end()) {
			places[place] = { place, info, x, y, width, height, {} };  // 创建地点并初始化道路为空
			loadimage(&places[place].img, pfile);
			numPlaces++; // 增加地点数量
		}
	}
	void addPlace(const string& place, const string& info, int x, int y, int width, int height) {
		// 如果地点名称在映射中不存在，则添加新地点
		if (places.find(place) == places.end()) {
			places[place] = { place, info, x, y, width, height, {} };  // 创建地点并初始化道路为空
			numPlaces++; // 增加地点数量
		}
	}
	// 从地图中删除一个地点
	void deletePlace(const string& place) {
		// 如果地点名称在映射中存在，则删除地点
		if (places.find(place) != places.end()) {
			// 遍历所有地点，删除与被删除地点相连的道路
			for (auto& p : places) {
				p.second.roads.erase(getIndex(place));
			}
			places.erase(place);  // 从映射中删除地点
			numPlaces--;          // 减少地点数量
			Notice = "景点删除：" + place;  // 输出删除信息
		}
		else {
			Notice = "没有找到景点." ;  // 如果地点不存在，输出错误信息
		}
	}
	bool isinPlaces(ExMessage& m, string& s)
	{
		if (m.message == WM_LBUTTONDOWN)
		{

			for (const auto& entry : places) {
				const auto& place = entry.second;  // 获取地点信息
				if (m.x > place.x && m.x<place.x + place.width
					&& m.y>place.y && m.y < place.y + place.height)
				{
					cout<<"find";
					s = place.name;
					return 1;
				}
			}
		}
		return 0;
	}
	void findplace(string s, int& x, int& y, int& wid, int& hei)
	{
		for (const auto& entry : places) {
			const auto& place = entry.second;  // 获取地点信息
			if (s == place.name)
			{
				x = place.x;
				y = place.y;
				wid = place.width;
				hei = place.height;
				break;
			}
		}
	}
	// 在两个地点之间添加道路
	void addRoad(const string& place1, const string& place2, int distance) {
		if (places.find(place1) != places.end() && places.find(place2) != places.end()) {
			int index1 = getIndex(place1);
			int index2 = getIndex(place2);
			places[place1].roads[index2] = distance;
			places[place2].roads[index1] = distance;
			char S[25];
			_itoa_s(distance, S, 10);

			Notice = "存在道路，在 '" + place1 + "' 和 '" + place2 + "' 之间存在道路，" + " 距离为：" + S + " 个单位";
		}
		else {
			Notice = "不存在输入的1或2个景点，请检查输入." ;
		}
	}

	void deleteRoad(const string& place1, const string& place2) {
		// 如果两个地点都存在于映射中，则添加道路
		if (places.find(place1) != places.end() && places.find(place2) != places.end()) {
			int index1 = getIndex(place1);  // 获取第一个地点的索引
			int index2 = getIndex(place2);  // 获取第二个地点的索引
			removeRoad(index1, index2);     // 在第一个地点的道路映射中添加第二个地点
			removeRoad(index2, index1);     // 在第二个地点的道路映射中添加第一个地点
			Notice = "删除在'" + place1 + "'和'" + place2 + "'之间的道路" ;  // 输出添加道路的信息
		}
		else {
			Notice = "不存在输入的1或2个景点，请检查输入.";  // 如果任一地点不存在，输出错误信息
		}
	}

	// 显示地图上所有地点及其连接的道路
	void displayRoads() {
		// 遍历所有地点
		for (const auto& entry : places) {
			const auto& place = entry.second;  // 获取地点信息
			s_allpath += place.name + " (" + place.info + ")/n";
			s_allpath += "路径：/n" ;
			for (const auto& road : place.roads) {
				const auto& connectedPlace = places[getPlaceName(road.first)];
				{
					char S[25];
					_itoa_s(road.second, S, 10);
					s_allpath += " -> " + connectedPlace.name + " (距离：" + S + ")";
				}
			}
		}
		Notice = "提示tip：校园地图如上所示" ;
	}

	// 根据地点索引获取地点名称
	Place getPlace(int index) {
		// 使用迭代器 
		auto it = places.begin();
		advance(it, index);
		return it->second;  // 返回迭代器指向的地点
	}

	void queryPlace(const string& place) {
		if (places.find(place) != places.end()) {
			const auto& info = places[place].info;
			int index = 0;

			for (auto it = places.begin(); it != places.end(); ++it, ++index) {
				if (it->first == place) {
					break;
				}
			}
			order = index;
		}
		else {
			Notice = "没有找到景点.";
		}
	}

	void queryPath(const string& place1, const string& place2) {
		if (places.find(place1) != places.end() && places.find(place2) != places.end()) {
			//最短路径使用 Dijkstra算法
			unordered_map<string, int> dist;
			unordered_map<string, string> prev;
			auto cmp = [&dist](const string& left, const string& right) { return dist[left] > dist[right]; };
			priority_queue<string, vector<string>, decltype(cmp)> pq(cmp);

			for (const auto& entry : places) {
				dist[entry.first] = INF;
				prev[entry.first] = "";
			}

			dist[place1] = 0;
			pq.push(place1);

			while (!pq.empty()) {
				string u = pq.top();
				pq.pop();

				if (u == place2) break;

				for (const auto& neighbor : places[u].roads) {
					string v = getPlaceName(neighbor.first);
					int weight = neighbor.second;
					int alt = dist[u] + weight;

					if (alt < dist[v]) {
						dist[v] = alt;
						prev[v] = u;
						pq.push(v);
					}
				}
			}

			if (dist[place2] == INF) {
				Notice = "这里没有路径从 ";
				Notice += place1 + " 到 " + place2 + ".";
			}
			else {
				char S[25];
				_itoa_s(dist[place2], S, 10);
				s_shortpath = "最短路径从";
				s_shortpath += place1 + "到" + place2 + "是：" + S + "个单位." ;
				vector<string> path;
				for (string at = place2; at != ""; at = prev[at]) {
					path.push_back(at);
				}
				reverse(path.begin(), path.end());
				for (const string& p : path) {
					s_shortpath += p;
					if (p != place2) s_shortpath += "-> ";
				}
			}

			//DFS
			vector<string> currentPath;
			vector<vector<string>> allPaths;
			unordered_map<string, bool> visited;

			currentPath.push_back(place1);
			dfs(place1, place2, currentPath, allPaths, visited);

			s_allpath ="所有路径从:";
			s_allpath += place1 + "到" + place2 + ":";
			for (const auto& path : allPaths) {
				for (size_t i = 0; i < path.size(); ++i) {
					s_allpath += path[i];
					if (i != path.size() - 1) s_allpath += " -> ";
				}
			}
		}
		else {
			MessageBox(GetHWnd(), "不存在输入的1或2个景点，请检查输入.", " 校园景点导游系统", MB_OK);
		}
	}
};
enum Operatormaster
{
	resize,
	roadnum,
	closeroad,
	closearea,
	old = -1
};
enum Operatorvistor
{
	display,
	search1,
	search2,
	xysap,
	eror = -1
};
void initmap(CampusMap& campus);
int mastermenu(vector<Button*>& bts, ExMessage& msg);
int vistormenu(vector<Button*>& bts, ExMessage& msg);

//各个按钮的功能实现
void Resize(CampusMap& campus1, CampusMap& campus2);//增删景点
void Roadnum(CampusMap& campus1, CampusMap& campus2, ExMessage& m);//增删道路
void Closeroad(CampusMap& campus);//封闭道路
void Closearea(CampusMap& campus);//闭园
void Mastermenu(vector<Button*>& bts, ExMessage& msg, CampusMap& campus);

void displayall(CampusMap& campus);
void searchplace(CampusMap& campus);
void searchpath(CampusMap& campus);
void VisitorMenu(vector<Button*>& bts, ExMessage& msg, CampusMap& campus);//游客登录

//所有的按钮绘制
void FlushButton(vector<Button*>& bts, ExMessage& msg);
void UIchange(int& t, vector<Button*>& bts, CampusMap& campus);
void initmap(CampusMap& campus);
void initall(CampusMap& campus);
//开始操作
void maketrue(vector<Button*>& bts, CampusMap& campus1, CampusMap& campus2);

//初始背景
void background();

//开始窗口选择
int checkID();

int main()
{
	initgraph(w_width, w_height);
	SetWindowText(GetHWnd(), "校园景点导游");
	vector<Button*>bts;
	CampusMap initcampus, allcampus;

	maketrue(bts, initcampus, allcampus);
	while (1);
	closegraph();
	return 0;
}

void background()
{
	IMAGE img;
	loadimage(&img, "bk1.jpg");
	putimage(0, 0, &img);
}

int checkID()
{
	int flag = 0;
label_1:
	char s[20];
	string str;
	InputBox(s, 20, "Please Enter your ID", "身份验证", "202407");
	if ((string)s == IDName)
	{
	label_2:
		char s1[20];
		InputBox(s1, 15, "Please Enter Passward", "身份验证", "123456");
		if ((string)s1 == IDpassward)
		{
			MessageBox(GetHWnd(), "验证成功，欢迎使用", " 管理身份验证", MB_OK);
			flag = 1;
		}
		else
		{
			int res1 = MessageBox(GetHWnd(), "密码错误，是否重试", " 管理身份验证", MB_YESNO);
			{
				if (res1 == IDYES)
					goto label_2;
			}
		}
	}
	else
	{
		int res = MessageBox(GetHWnd(), "不存在该账号，是否重试", " 管理身份验证", MB_YESNO);
		{
			if (res == IDYES)
				goto label_1;
		}
	}
	return flag;
}

Button::Button(int x, int y, int width, int height, const string text)
{
	this->x = x;
	this->y = y;
	this->width = width;
	this->height = height;
	this->outColor = WHITE;
	this->inColor = GREEN;
	this->text = text;
	this->textColor = BLACK;
}
void drawbuttonarea(Button& b)
{
	//画矩形
	setfillcolor(b.outColor);
	setlinecolor(BLACK);
	fillroundrect(b.x, b.y, b.x + b.width, b.y + b.height, 15, 15);

	int textWidth = textwidth(b.text.c_str());
	int textHeight = textheight(b.text.c_str());
	int tx = b.x + (b.width - textWidth) / 2;
	int ty = b.y + (b.height - textHeight) / 2;
	setbkmode(TRANSPARENT);
	settextcolor(b.textColor);
	outtextxy(tx, ty, b.text.c_str());
}
int clickButton(Button& b, ExMessage m)
{
	peekmessage(&m, EX_MOUSE);
	if (m.x >= b.x && m.x <= b.x + b.width &&
		m.y >= b.y && m.y <= b.y + b.height
		&& m.message == WM_LBUTTONDOWN)
	{
		b.outColor = GREEN;
		return 1;
	}
	else
		b.outColor = WHITE;
	return 0;
}

int mastormenu(vector<Button*>& bts, ExMessage& m)
{
	peekmessage(&m, EX_MOUSE);
	for (int i = 2; i < 6; i++)
	{
		if (clickButton(*bts[i], m))
			return i - 2;
	}
	return old;
}
int vistormenu(vector<Button*>& bts, ExMessage& m)
{
	peekmessage(&m, EX_MOUSE);
	for (int i = 6; i < 10; i++)
	{
		if (clickButton(*bts[i], m))
			return i - 6;
	}
	return old;
}
void Resize(CampusMap& campus1, CampusMap& campus2)
{
	ExMessage m;
	int t = 0;
	while (t == 0)
	{
		while (peekmessage(&m, EX_MOUSE | EX_KEY))
		{
			if (m.message == WM_KEYDOWN)
			{
				if (m.vkcode == VK_ESCAPE)
				{
					t = 1;
				}
			}
		}
		string place, info;
		int x, y, width, height;
		int t = 0;
		if (campus1.isinPlaces(m, place))
		{
			int res = MessageBox(GetHWnd(), "是否删除", "提示", MB_YESNO);
			if (res == IDYES)
			{
				int x, y, w, h;
				campus1.findplace(place, x, y, w, h);
				campus1.deletePlace(place);
				campus2.addPlace(place, " ", x, y, w, h);
			}
		}
		else if (campus2.isinPlaces(m, place))
		{
			char s[200], ss[200];
			InputBox(s, 200, "增加景点--名称", "后台控制");
			InputBox(ss, 200, "增加景点--景点介绍", "后台控制");
			place = (string)s;
			info = (string)ss;

			campus2.findplace(place, x, y, width, height);
			campus1.addPlace(place, info, x, y, width, height);
			campus2.deletePlace(place);
		}
		Sleep(100);
	}
}
void peek(ExMessage& m, int& t)
{
	while(t == 0)
	{
		while (peekmessage(&m, EX_MOUSE | EX_KEY))
		{
			if (m.message == WM_KEYDOWN)
			{
				if (m.vkcode == VK_ESCAPE)
				{
					t = 1;
				}
			}
		}
	}

}
void Roadnum(CampusMap& campus1, CampusMap& campus2, ExMessage& m)
{
	;
	int t = 0, flag = 0;
		string place1, place2;
		int i = 0;
		thread th2(peek, ref(m),ref(t));
	while (t == 0)
	{
		int distance;
		string place;
			if (campus2.isinPlaces(m, place))
			{
				MessageBox(GetHWnd(), "该景点/地点未开放", "警告", MB_OK);
			}
			if (flag == 0)
			{
				if(campus1.isinPlaces(m, place1))
				{
					flag = 1;
				}
			}
			else if (flag == 1)
			{
				if(campus1.isinPlaces(m, place2))
				{
					flag = 2;
				}
			}
			else if (flag == 2)
			{
				int res = MessageBox(GetHWnd(), "增加道路 或 减少道路", "后台控制", MB_YESNO);
				if (res == IDYES)
				{
					if (place1 != place2)
					{
						char s[5];
						InputBox(s, 3, "增加路径", "后台控制");
						sscanf_s(s, "%d", &distance);
						campus1.addRoad(place1, place2, distance);
					}
				}
				else
				{
					campus1.deleteRoad(place1, place2);
				}
				t = 1;
			}
		Sleep(100);
	}
	th2.detach();
}
void Closeroad(CampusMap& campus)
{
	cout << "Closeroad" << endl;
}
void Closearea(CampusMap& campus)
{
	cout << "Closearea" << endl;
}
void MasterMenu(vector<Button*>& bts, ExMessage& m, CampusMap& campus1, CampusMap& campus2)
{
	int op = old;
	int flag = 1;
	string s;
	int t = 0;
	while (flag)
	{
		while (peekmessage(&m, EX_KEY | EX_MOUSE))
		{
			if (campus1.isinPlaces(m, s))
				cout << s;
			if (m.message == WM_KEYDOWN)
			{
				if (m.vkcode == VK_ESCAPE)
				{
					if (op == old)
					{
						flag = 0;
					}
					op = old;
				}
			}
		}
		switch (op)
		{
		case old:
			s_allpath = "";
			s_shortpath = "";
			Notice = "";
			op = mastormenu(bts, m);
			break;
		case resize:
			Resize(campus1, campus2);
			break;
		case roadnum:
			Roadnum(campus1, campus2, m);
			break;
		case closeroad:
			Closeroad(campus1);
			break;
		case closearea:
			Closearea(campus1);
			break;
		default:
			break;
		}
		Sleep(100);
	}
	cleardevice();
}
void displayall(CampusMap& campus)
{
	ExMessage m;
	int t = 0;
	s_allpath = "校园地图：/n";
	campus.displayRoads();
	while (t == 0)
	{
		while (peekmessage(&m, EX_MOUSE | EX_KEY))
		{
			if (m.message == WM_KEYDOWN)
			{
				if (m.vkcode == VK_ESCAPE)
				{
					t = 1;
				}
			}
		}
		Sleep(100);
	}
}
void searchplace(CampusMap& campus)
{
	ExMessage m;
	int t = 0;
	while (t == 0)
	{
		while (peekmessage(&m, EX_MOUSE | EX_KEY))
		{
			if (m.message == WM_KEYDOWN)
			{
				if (m.vkcode == VK_ESCAPE)
				{
					t = 1;
					order = -1;
				}
			}
		}

		string place;
		if (campus.isinPlaces(m, place))
		{
			campus.queryPlace(place);
		}
		Sleep(100);
	}
}
void searchnext(CampusMap& campus, string& s, int& t)
{
	ExMessage m;
	while (t == 0)
	{
		while (peekmessage(&m, EX_MOUSE))
		{
			campus.isinPlaces(m, s);
		}
		Sleep(100);
	}
}
void searchpath(CampusMap& campus)
{
	ExMessage m, msg;
	int t = 0;
		string place1, place2;
		thread th(searchnext, ref(campus), ref(place2), ref(t));
	while (t == 0)
	{
		while (peekmessage(&m, EX_MOUSE | EX_KEY))
		{
			if (m.message == WM_KEYDOWN)
			{
				if (m.vkcode == VK_ESCAPE)
				{
					t = 1;
				}
			}
		}

		campus.isinPlaces(m, place1);
		if(!place1.empty() && !place2.empty())
		{
			campus.queryPath(place1, place2);
		}

		Sleep(100);
	}
	th.detach();
}
void mapsap()
{
	int t = 0;
		float dp = 1;
	while (t == 0)
	{

		ExMessage m;
		IMAGE img, img1;
		loadimage(&img, "map1.jpg");
		while (peekmessage(&m, EX_MOUSE | EX_KEY))
		{
			if (m.message == WM_KEYDOWN)
			{
				if (m.vkcode == VK_ESCAPE)
				{
					t = 1;
				}
			}
			if (m.message == WM_MOUSEWHEEL)
			{
				if (m.wheel > 0)
					dp += 0.1;
				else
				{
					if (dp > 1)
					{
						dp -= 0.1;
					}
				}
			}
			cout << dp;
			setaspectratio(dp, dp);
		}
		setorigin(0, 0);
		loadimage(&img1, "bk.jpg");
		putimage(0, 0, &img);
		putimage(w_width - b_width * 2 - 5, 0, &img1);
		Sleep(100);
	}
}
void VisitorMenu(vector<Button*>& bts, ExMessage& m, CampusMap& campus)
{
	int flag = 1, op = eror;
	while (flag)
	{
		while (peekmessage(&m, EX_KEY | EX_MOUSE))
		{
			if (m.message == WM_KEYDOWN)
			{
				if (m.vkcode == VK_ESCAPE)
				{
					background();
					if (op == eror)
					{
						flag = 0;
					}
				}
			}
		}
		switch (op)
		{
		case eror:
			s_allpath = "";
			s_shortpath = "";
			Notice = "";
			op = vistormenu(bts, m);
			break;
		case display:
			displayall(campus);
			op = eror;
			break;
		case search1:
			searchplace(campus);
			op = eror;
			break;
		case search2:
			searchpath(campus);
			op = eror;
			break;
		case xysap:
			mapsap();
			op = eror;
			break;
		default:
			break;
		}
		Sleep(100);
	}
	cleardevice();
}
void FlushButton(vector<Button*>& bts, ExMessage& msg)
{
	int x = (w_width - b_width);
	int y = (w_height - 2 * b_height) / 2;
	//管理端界面按钮
	bts.push_back(new Button(x - b_width, 0, b_width, b_height, "管理员"));
	//游客端
	bts.push_back(new Button(x, 0, b_width, b_height, "游客"));
	int xx = w_width - 120;
	bts.push_back(new Button(xx, (4 + num++) * b_height, b_width, b_height, "增删景点"));
	bts.push_back(new Button(xx, (5 + num++) * b_height, b_width, b_height, "扩增道路"));
	bts.push_back(new Button(xx, (6 + num++) * b_height, b_width, b_height, "封停道路"));
	bts.push_back(new Button(xx, (7 + num++) * b_height, b_width, b_height, "暂停开放"));
	bts.push_back(new Button(xx, (1 + num++) * b_height, b_width, b_height, "查看道路"));
	bts.push_back(new Button(xx, (2 + num++) * b_height, b_width, b_height, "查看景点"));
	bts.push_back(new Button(xx, (3 + num++) * b_height, b_width, b_height, "选择景点"));
	bts.push_back(new Button(xx, (4 + num++) * b_height, b_width, b_height, "地图缩放"));

}
void UIchange(int& t, vector<Button*>& bts, CampusMap& campus)
{
	BeginBatchDraw();
	while (1)
	{
		if (bts.size() > 8)
		{
			if (t == 0)
			{
				background();
				string text = "欢迎来到";
				string text2 = "武汉大学校园导游系统";
				settextstyle(80, 0, "隶书");
				int textWidth1 = textwidth(text.c_str());
				int textHeight1 = textheight(text.c_str());
				int textWidth2 = textwidth(text2.c_str());
				int textHeight2 = textheight(text2.c_str());
				int tx1 = 430 + (200 - textWidth1) / 2;
				int ty1 = 280 + (0 - textHeight1) / 2;
				int tx2 = 450 + (100 - textWidth2) / 2;
				int ty2 = 350 + (50 - textHeight2) / 2;
				setbkmode(TRANSPARENT);
				settextcolor(WHITE);
				outtextxy(tx1, ty1, text.c_str());
				outtextxy(tx2, ty2, text2.c_str());
				settextstyle(20,0, "宋体");
				for (int i = 0; i < 2; i++)
					drawbuttonarea(*bts[i]);
			}
			else
			{
				if(order == -1)
				{
					BeginBatchDraw();
					IMAGE img, img1;
					loadimage(&img, "map1.jpg");
					loadimage(&img1, "bk.jpg");
					putimage(0, 0, &img);
					putimage(w_width - b_width * 2 - 5, 0, &img1);

					if (t == 1)
					{
						for (int i = 2; i < 4; i++)
							drawbuttonarea(*bts[i]);
					}
					else if (t == 2)
					{
						for (int i = 6; i < 10; i++)
							drawbuttonarea(*bts[i]);
					}
					if (!s_allpath.empty())
					{
						char ch[1000];
						strcpy_s(ch, s_allpath.data());
						outtextxy(0, 30, ch);
						s_allpath = "";
					}
					if (!s_shortpath.empty())
					{
						char ch[300];
						strcpy_s(ch, s_shortpath.data());
						outtextxy(0, 60, ch);
						s_shortpath = "";
					}
					if (!Notice.empty())
					{
						char ch[300];
						strcpy_s(ch, Notice.data());
						outtextxy(0, 0, ch);
					}
					Sleep(100);
				}
				else
				{
					Place p = campus.getPlace(order);
					putimage(0, 0, &p.img);
				}
			}
		}
		FlushBatchDraw();
	}
	EndBatchDraw();
}
void initmap(CampusMap& campus)
{
	IMAGE img[10];
	campus.initPlace("珞珈门", "珞珈门的详细介绍", 170, 380, 40, 30, "珞珈门.jpg");
	campus.initPlace("星湖", "星湖的详细介绍", 230, 550, 50, 40, "星湖.jpg");
	campus.initPlace("珞瑜门", "珞瑜门的详细介绍", 270, 650, 40, 30, "珞瑜门.jpg");
	campus.initPlace("珞珈广场", "珞珈广场的详细介绍", 230, 350, 40, 30, "珞珈广场.jpg");
	campus.initPlace("茶港门", "茶港门的详细介绍", 60, 185, 40, 30, "茶港门.jpg");
	campus.initPlace("樱园", "樱园的详细介绍", 320, 200, 40, 30, "樱园.jpg");
	campus.initPlace("喷泉广场", "喷泉广场的详细介绍", 300, 50, 50, 40, "喷泉广场.jpg");
	campus.initPlace("月湖", "月湖的详细介绍", 620, 130, 40, 30, "月湖.jpg");
	campus.initPlace("凌波门", "凌波门的详细介绍", 590, 45, 50, 40, "凌波门.jpg");
	campus.initPlace("珞珈山", "珞珈山的详细介绍", 550, 360, 40, 40, "珞珈山.jpg");

	campus.addRoad("珞珈门", "星湖", 5);
	campus.addRoad("星湖", "珞瑜门", 3);
	campus.addRoad("樱园", "珞珈广场", 7);
	campus.addRoad("珞珈门", "珞珈广场", 2);
	campus.addRoad("茶港门", "珞珈门", 6);
	campus.addRoad("樱园", "珞珈广场", 5);
	campus.addRoad("喷泉广场", "樱园", 4);
	campus.addRoad("月湖", "珞珈山", 6);
	campus.addRoad("凌波门", "月湖", 2);
	campus.addRoad("珞珈山", "珞珈广场", 10);
}
void initall(CampusMap& campus)
{
	campus.addPlace("国软小门", "国软小门的详细介绍", 130, 500, 40, 30);
	campus.addPlace("珞瑜二门", "珞瑜二门的详细介绍", 165, 600, 40, 30);
	campus.addPlace("珞南门", "珞南门的详细介绍", 320, 430, 40, 30);
	campus.addPlace("西南门", "西南门的详细介绍", 320, 480, 40, 30);
	campus.addPlace("珞南三门", "珞南三门的详细介绍", 400, 460, 40, 20);
	campus.addPlace("扬波门", "扬波门的详细介绍", 775, 325, 40, 30);
	campus.addPlace("枫园", "枫园的详细介绍", 625, 235, 40, 30);
	campus.addPlace("湖滨", "湖滨的详细介绍", 588, 120, 30, 23);
	campus.addPlace("半边山", "半边山的详细介绍", 612, 107, 20, 15);
	campus.addPlace("洪波门", "洪波门的详细介绍", 430, 10, 40, 20);
	campus.addPlace("松园", "松园的详细介绍", 420, 42, 40, 20);
	campus.addPlace("澄波门", "澄波门的详细介绍", 290, 15, 40, 17);
	campus.addPlace("文澜门", "文澜门的详细介绍", 270, 10, 20, 20);
	campus.addPlace("世纪广场", "世纪广场的详细介绍", 268, 103, 30, 20);
	campus.addPlace("桂园", "桂园的详细介绍", 243, 236, 30, 20);
	campus.addPlace("鉴心湖", "鉴心湖的详细介绍", 325, 238, 30, 20);
	campus.addPlace("梅园", "梅园的详细介绍", 380, 240, 30, 20);
}
void maketrue(vector<Button*>& bts, CampusMap& campus1, CampusMap& campus2)
{
	int temp = 0;
	string s;
	initmap(campus1);
	initall(campus2);
	ExMessage msg;
	FlushButton(bts, msg);
	thread th2(UIchange, ref(temp), ref(bts), ref(campus1));
	while (1)
	{
		while (peekmessage(&msg, EX_KEY | EX_MOUSE))
		{
			if (bts.size() > 8)
			{
				if (clickButton(*bts[0], msg))
				{
					if (checkID())
					{
						temp = 1;
						MasterMenu(bts, msg, campus1, campus2);
					}
				}
				else if (clickButton(*bts[1], msg))
				{
					temp = 2;
					VisitorMenu(bts, msg, campus1);
				}
			}
			temp = 0;
		}
		Sleep(100);
	}
	th2.detach();
}